#ifndef _FNT_DECIMATE_HH_
#define _FNT_DECIMATE_HH_

#include <list>
#include <array>

namespace detail {
	struct Node {
		std::array<double, 3> pos;
		double a;
		std::size_t i;
	};
	void reducePointsImpl(std::list<Node>& pts, double maxdist, double maxarea);
}

template<typename FwdIt>
FwdIt reducePoints(FwdIt first, FwdIt last, double maxdist, double maxarea) {
	std::list<detail::Node> pts{};
	std::size_t i=0;
	for(auto it=first; it!=last; it++)
		pts.emplace_back(detail::Node{it->x(), it->y(), it->z(), 0.0, i++});
	detail::reducePointsImpl(pts, maxdist, maxarea);
	i=0;
	FwdIt it0=first, it1=first;
	for(auto& pt: pts) {
		while(i++<pt.i)
			it0++;
		if(it0!=it1)
			*it1=*it0;
		it0++;
		it1++;
	}
	return it1;
}

#endif
